package org.summerframework.component.security.enumeration;

/**
 * 登录帐号类型
 *
 * @author 石超
 * @version v1.0.0
 */
public enum LoginAccountEnum {
    //登录帐号类型
    LOGIN_ERROR(-1, "不认识的登录方式", "public/error"),
    LOGIN_NAME(1, "name登录", "name"),
    LOGIN_MOBILE(2, "mobile登录", "mobile"),
    LOGIN_EMAIL(3, "email登录", "email");

    /**
     * 类型
     */
    private int type;

    /**
     * 类型描述
     */
    private String typeStr;

    /**
     * 类型code
     */
    private String typeCode;

    LoginAccountEnum(int type, String typeStr, String typeCode) {
        this.type = type;
        this.typeStr = typeStr;
        this.typeCode = typeCode;
    }

    /**
     * 根据id返回类型enum
     *
     * @param type
     * @return
     */
    public static LoginAccountEnum getLoginType(int type) {
        for (LoginAccountEnum lt : values()) {
            if (lt.type == type) {
                return lt;
            }
        }
        return LOGIN_ERROR;
    }

    /**
     * 根据typeCode返回类型enum
     *
     * @param typeCode
     * @return
     */
    public static LoginAccountEnum getLoginByCode(String typeCode) {
        for (LoginAccountEnum lt : values()) {
            if (lt.typeCode.equalsIgnoreCase(typeCode)) {
                return lt;
            }
        }
        return LOGIN_ERROR;
    }

    public int getType() {
        return type;
    }

    public String getTypeStr() {
        return typeStr;
    }

    public String getTypeCode() {
        return typeCode;
    }

}
